﻿Imports System
Imports System.Windows
Imports System.Windows.Controls

Partial Public Class InputWindow
    Inherits ChildWindow

    Public Enum EnumTipus
        TextBox
        PasswordBox
    End Enum

    Private _Input As String = ""
    Public ReadOnly Property Input As String
        Get
            Return _Input
        End Get
    End Property

    Private _Tipus As EnumTipus = EnumTipus.TextBox
    Public ReadOnly Property Tipus As EnumTipus
        Get
            Return _Tipus
        End Get
    End Property

    Public Sub New()

        ' Llamada necesaria para el Diseñador de Windows Forms.
        InitializeComponent()

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().

    End Sub



    Public Sub New(ByVal message As String, pTipus As EnumTipus)
        InitializeComponent()
        _Tipus = pTipus
        Informacion.Text = message
    End Sub

    Private Sub InputWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        If Tipus = EnumTipus.TextBox Then
            txtInput.Visibility = Windows.Visibility.Visible
        ElseIf Tipus = EnumTipus.PasswordBox Then
            pwdInput.Visibility = Windows.Visibility.Visible
        End If
    End Sub

    Private Sub OKButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles OkButton.Click
        If Tipus = EnumTipus.TextBox Then
            _Input = txtInput.Text
        ElseIf Tipus = EnumTipus.PasswordBox Then
            _Input = pwdInput.Password
        End If

        Me.DialogResult = True
    End Sub

    Private Sub CancelButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles CancelButton.Click
        Me.DialogResult = False
    End Sub

    Private Sub Child_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Closed
        Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, True)
    End Sub

    Private Sub input_KeyDown(sender As System.Object, e As System.Windows.Input.KeyEventArgs)
        If e.Key = Key.Enter Then
            OKButton_Click(Nothing, Nothing)
        ElseIf e.Key = Key.Escape Then
            CancelButton_Click(Nothing, Nothing)
        End If
    End Sub

End Class
